const util = require('../../../utils/util.js')
var xrSdk = require('../../../vendor/hope-sdk/index.js');
Page({
  data: {
    history: [
      "冬季轿车轮胎",
      "耐磨型",
      "高性能轮胎",
      "城市型SUV"
    ],
    hot: [
      "德利赫特",
      "托雷斯",
      "早安D站",
      "D站观点",
      "德利赫特",
      "美洲杯",
      "华为手机",
      "C罗",
      "自热火锅",
      "2019退役球星",
      "女神大会"
    ],
    key: "",
    showActionSheet: false,
    tips: "确认清空搜索历史吗？"
  },
  onLoad: function (options) {

  },
  back: function () {
    wx.navigateBack();
  },
  input: function (e) {
    let key = util.trim(e.detail.value);
    this.setData({
      key: key
    })
  },
  cleanKey: function () {
    this.setData({
      key: ''
    });
  },
  closeActionSheet: function () {
    this.setData({
      showActionSheet: false
    })
  },
  openActionSheet: function () {
    this.setData({
      showActionSheet: true
    })
  },
  itemClick: function (e) {
    let index = e.detail.index;
    if (index == 0) {
      this.setData({
        showActionSheet: false,
        history: []
      })
    }
  },
  search: function (e) {
    var key = e.detail.value;
    this.searchHandle(key);
  },
  searchKeyword: function (e) {
    var key = e.currentTarget.dataset.key;
    this.searchHandle(key);
  },
  searchHandle:function(key){
    var pages = getCurrentPages(); //取到页面
    var prevPage = pages[pages.length - 2]; //上一个页面
    console.log(prevPage);
    if (prevPage.route == 'pages/goods/list/list') {
      prevPage.setData({
        searchKey: key,
      }, function () {
        wx.navigateBack({
          delta: 1
        });
      });
    } else {
      wx.redirectTo({
        url: '../list/list?searchKey=' + key
      })
    }
  }
})